home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
swagg_m.zip
/
MATH.SWG
/
0072_Prime Numbers.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-08-24
|
850b
|
29 lines
{
I'm studying pascal on my own and was given an assignment to determine if a
positive number is prime. This was in a chapter where functions were
discussed. I've struggled with this problem for a week and have given up. The
following code is the best I can come up with. It is not correct. Would
someone please evaluate this and tell me what is wrong with it?
}
PROGRAM PrimeNumbers;
{ Exercise to determine if a positive number is a prime }
VAR x : WORD;
FUNCTION prime (p : WORD) : BOOLEAN;
BEGIN { Prime }
prime := (p MOD 2 <> 0) AND (p MOD 3 <> 0) AND (p MOD 5 <> 0)
END; { Prime }
BEGIN { Main }
REPEAT
WRITE ('Enter a positive number. 0 to quit: ');
READLN (x);
IF prime (x) THEN
WRITELN (x, ' is a prime number')
ELSE
WRITELN (x, ' is NOT prime');
UNTIL
x = 0
END. { Main }